<?php
/*  This file is part of opinhost.
 *
 *  opinhost is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  opinhost is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with opinhost.  If not, see <http://www.gnu.org/licenses/>.
 */
include("include/config.php");
require 'libs/Smarty.class.php';
error_reporting(E_ALL);
$result = "<h2>TCP/IP Connection</h2>\n";
$smarty = new Smarty;

$smarty->compile_check = $themede;
$smarty->debugging = $themecc;
//Setup Client
$host=$_POST['server_ip'];
$port = $_POST['server_port'];
$message = $_POST['command'];
//open a client connection
$fp = fsockopen($host,$port,$errno,$errstr);

if(!$fp)
{
	$result = "Error: could not open socket connection\r\n".
			  "Host: ".$host."\r\n".
			  "Port: ".$port."\r\n".
			  "Command: ".$message;
}
else
{
	//write the user string to the socket
	fputs($fp, $message."<EOF>");
	//get the result
	//First Line Contains Amount of Lines
	$lines = fgets($fp, 1024);
	$rlines = 0;
	while($rlines <> $lines){
		$lendstr = fgets($fp, 1024);
		$result .= $lendstr;
		$result .= "<br>";
		$rlines++;
	}
	//close the connection
	//fputs($fp, "END");
	fclose($fp);
}
$smarty->assign("Content", $result);

$smarty->display($themear["index.php"]);
?>